package com.export.netty.inithandler;

import com.export.netty.filterhandler.BusinessFullHandler;
import com.rlyy.aibase.netty.codec.HttpJsonRequestDecoder;
import com.rlyy.aibase.netty.codec.HttpJsonResponseEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import rsj.context.ApplicationContextUtil;
/**
 * @author       xuguoliang@rlyy.com
 * @date         2019/12/17 17:19
 * @description  NettyServer 初始化类
 * @package      com.example.netty.inithandler
 */
public class InitServerHandler extends ChannelInitializer<SocketChannel> {

    public InitServerHandler() {}

    @Override
    protected void initChannel(SocketChannel ch) {
        ch.pipeline().addLast("http-decoder", new HttpRequestDecoder());
        ch.pipeline().addLast("http-aggregator", new HttpObjectAggregator(65536));
        ch.pipeline().addLast("json-decoder", new HttpJsonRequestDecoder(Object.class, true));
        ch.pipeline().addLast("http-encoder", new HttpResponseEncoder());
        ch.pipeline().addLast("json-encoder", new HttpJsonResponseEncoder());
        ch.pipeline().addLast("jsonServerHandler", ApplicationContextUtil.getBean(BusinessFullHandler.class));
    }
}
